<template>
  <div class="login-wrap">
    <div class="ms-background"></div>
    <div class="ms-login">
      <h1>用户登录</h1>
      <el-form :model="ruleForm" ref="ruleForm" label-width="60px" class="demo-ruleForm">
        <el-form-item prop="username" label="账号:">
          <el-input v-model="ruleForm.username" placeholder="用户名是admin"></el-input>
        </el-form-item>
        <el-form-item prop="password" label="密码:">
          <el-input type="password" placeholder="密码是123456" v-model="ruleForm.password"></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="login()">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  name: "Login",
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      // rules: {
      //   username: [
      //     { required: true, message: "请输入用户名", trigger: "blur" },
      //   ],
      //   password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      // },
      loading: false,
    };
  },
  methods: {
    login() {
    if(this.ruleForm.username=="" || this.ruleForm.password==""){
      this.$message.error("用户名和密码不能为空")
    }else if(this.ruleForm.username=="admin"&&this.ruleForm.password=="123456"){
			window.localStorage.setItem("user",this.ruleForm.username)
			this.$router.push("/index")
		}else{
			this.$message.error("用户名和密码错误")
		}
		
    },
  },
  created() {
    let that = this;
    document.onkeydown = function (e) {
      e = window.event || e;
      if (
        that.$route.path == "/login" &&
        (e.code == "Enter" || e.code == "enter")
      ) {
        //验证在登录界面和按得键是回车键enter
        that.login(); //登录函数
      }
    };
  },
};
</script>
<style scoped>
.login-wrap {
  background-color: oldlace; 
  width: 1920px;
  height: 100vh;
  background-size: 100% 100%;
  background-position: center center;
  overflow: auto;
  position: relative;
}
.ms-background{
  position: absolute;
  background: url('../assets/images/login.jpg') no-repeat;
  background-size:cover;
  left: 10%;
  top:6%;
  width: 1080px;
  height: 787px;
}
h1{
  text-align: center;
}
.ms-login {
  position: absolute;
  left: 80%;
  top: 50%;
  width: 300px;
  height: 250px;
  line-height: 30px;
  margin: -150px 0 0 -190px;
  padding: 40px;
  border-radius: 5px;
  background: #fff;
  border: 1px solid #ccc;
}
.login-btn {
  text-align: right;
}
.login-btn button {
  width: 80%;
  height: 36px;
}
</style>